﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Wicture.QPZS.EPC.API.Domain.Entities;
using Wicture.QPZS.EPC.API.Repository;
using Wicture.QPZS.EPC.API.Throtteds.VinPrices;

namespace Wicture.QPZS.EPC.API.Throtteds
{
    public class PriceCostThrottled : CostThrottled
    {
        private readonly IServiceRepository _serviceRepository;
        private readonly IVinPriceProviderProxy _vinPriceProvider;

        public PriceCostThrottled(IServiceRepository serviceRepository, IVinPriceProviderProxy vinPriceProvider)
        {
            _serviceRepository = serviceRepository;
            _vinPriceProvider = vinPriceProvider;
        }

        public override List<ServicePackageType> ServicePackageTypes => new List<ServicePackageType> {
            ServicePackageType.计价
        };

        public override void InvokeMethod(ThrottlingContext context)
        {
            var cost = _vinPriceProvider.Provide(context);
            context.Cost = cost;
            _serviceRepository.CostBalance(context.AccountId, cost);
        }
    }
}
